package com.sys.core.utils;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class YaSuo {
	
	public void abc(HttpServletRequest request) throws IOException{
		File file = new File("");
		Image img = ImageIO.read(file);
		Integer imgwidth = img.getWidth(null);
		Integer imgheight = img.getHeight(null);
		//为等比缩放计算输出的图片宽度及高度
		int width =200;
		int height = (imgheight*200)/imgwidth;
		BufferedImage b1= new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		Graphics g= b1.getGraphics();
		g.drawImage(img.getScaledInstance(width, height, Image.SCALE_SMOOTH),0,0,null);
		g.dispose();
		String toUri ="/static/images/chezhujie/icon/luckpai";
		String toPath = request.getSession().getServletContext().getRealPath(toUri);
		File f2 = new File(toPath);
		if(!f2.exists() && !f2.isDirectory()){
			f2.mkdir();
			toPath = request.getSession().getServletContext().getRealPath(toUri);
		}
		System.out.println("toPath:"+toPath+"/"+file);
		File tofFile = new File(toPath+"/"+file);
		ImageIO.write(b1, "jpg", tofFile);		
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
